import { API_LIST } from '../../../Api/Api'
import { Tag } from 'antd'
import { commonTableList, BuiltInData } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton, OpenTwoRouter } from '../Common/options'

export const InfoCloudDisks = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    let data = {
        pageSize: 10,
        params: { pageIndex: 1 },
        get: API_LIST()[`get${url}`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [<AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增" />],
        columns: [
            commonTableList.uuid,
            {
                dataIndex: 'dataType',
                title: '类型',
                valueType: 'input',
                ellipsis: true,
                rules: true,
                width: 80,
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true,
                render: (_, { dataType }) => {
                    if (dataType === '自有') return <Tag color="#2db7f5">{dataType}</Tag>
                    else return <Tag color="#87d068">{dataType}</Tag>
                },
            },
            {
                dataIndex: 'tableName',
                title: '主题',
                valueType: 'input',
                ellipsis: true,
                rules: true,
                width: 150,
            },
            commonTableList.createUserName,
            commonTableList.createTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 320,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { dataType } = record
                    return [
                        dataType === '自有' && (
                            <OpenTwoRouter
                                key="A01"
                                title="分享人员"
                                modal="TableList"
                                OptionsEvent={OptionsEvent}
                                other={{
                                    page: 'AnnexPerson',
                                    actionRef,
                                    Permission,
                                    oneData: record,
                                    header: data.columns,
                                }}
                            />
                        ),
                        dataType === '自有' ? (
                            <OpenTwoRouter
                                key="A02"
                                title="附件管理"
                                modal="TableList"
                                OptionsEvent={OptionsEvent}
                                other={{
                                    page: 'AttachmentDetails',
                                    actionRef,
                                    Permission,
                                    oneData: record,
                                    header: data.columns,
                                }}
                            />
                        ) : (
                            <OpenTwoRouter
                                key="A02"
                                title="附件管理"
                                modal="TableList"
                                OptionsEvent={OptionsEvent}
                                other={{
                                    page: 'AttachmentDetailsOnly',
                                    actionRef,
                                    Permission,
                                    oneData: record,
                                    header: data.columns,
                                }}
                            />
                        ),
                        dataType === '自有' && (
                            <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" data={record} />
                        ),
                        dataType === '自有' && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }

    return data
}
